﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace MultiEnvironment.WebApplication1.Controllers
{
    /// <summary>
    /// 注入的方式读取配置文件
    /// </summary>
    /// <remark>
    /// <para/>Author   :  AnDequan
    /// <para/>Date     :  2019-12-25
    /// </remark>
    public class Home2Controller : Controller
    {
        private readonly IConfiguration _Configuration;

        public Home2Controller(IConfiguration configuration)
        {
            this._Configuration = configuration;

        }


        public IActionResult Index()
        {

            // An 2019-12-25 [ 显示当前环境变量 ]
            ViewBag.Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            // An 2019-12-25 [ 读取当前环境变量下配置文件中的节点 ]

            ViewBag.DefaultConnection = _Configuration["ConnectionString:Default"];


            return View();
        }
    }
}